package Servlet;
/*
@ClassName:     ServletList
@Author:        YangXu
@Need:          
@Date:          2022/4/27
@Time:          2022-04-27 17:31
*/

//


import entity.User;
import service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

@WebServlet("/userManage/UserList")
public class ServletList extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset-utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        System.out.println("接收到了请求");
        String txtUserName = req.getParameter("txtUserName");
        UserServiceImp userServiceImp = new UserServiceImp();
        userServiceImp.FindList(txtUserName);
        List<User> users = userServiceImp.FindList(txtUserName);
//        Iterator<User> iterator = users.iterator();
        
        req.setAttribute("list",users);

        req.getRequestDispatcher("/userList.jsp").forward(req,resp);
//        while(iterator.hasNext()) {
//            User next = iterator.next();
//            String username = next.getUsername();
//            String name = next.getName();
//            String job = next.getJob();
//            String deptName = next.getDeptName();
//            String updateTime = next.getUpdateTime();
////            req.setAttribute(updateTime,users);
//            System.out.println("添加结束");
//
//        }
        System.out.println("遍历结束");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
/*

 */